package com.example.batteryhelper;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;

import androidx.core.app.NotificationCompat;

public class NotificationHelper {
    private static final String CHANNEL_ID2 = "Channel2";
    public int notifId_1 = 0x1;
    public Context context;
    public NotificationHelper(Context context) {
        this.context=context;
    }

    public void notification() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            createNotificationChannel();//创建通道
            NotificationCompat.Builder repliedNotification = new NotificationCompat.Builder(context, CHANNEL_ID2);
            repliedNotification.setSmallIcon(R.drawable.ic_launcher_foreground)
                    .setContentText("用于查看当前功耗").setContentTitle("电流查看助手")
            .setOngoing(true);

            Notification notification = repliedNotification.build();
            NotificationManager mNotificationManager = context.getSystemService(NotificationManager.class);
            mNotificationManager.notify(notifId_1, notification);
        }
    }

    public void createNotificationChannel() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(CHANNEL_ID2, "退出界面显示的通知", importance);
            channel.setImportance(NotificationManager.IMPORTANCE_HIGH);//重要性
            channel.enableLights(false);
            channel.setSound(null, null);
            channel.enableVibration(false);
            NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }

    public void showPower(String i){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationCompat.Builder repliedNotification = new NotificationCompat.Builder(context, CHANNEL_ID2);
            repliedNotification.setSmallIcon(R.drawable.ic_launcher_foreground)
                    .setContentText(i).setContentTitle("电流查看助手")
            .setOngoing(true);

            Notification notification = repliedNotification.build();
            NotificationManager mNotificationManager = context.getSystemService(NotificationManager.class);
            mNotificationManager.notify(notifId_1, notification);
        }
    }
}
